﻿using Microsoft.AspNetCore.Mvc;
using MVC系统mvc.Dto.Process;
using MVC系统mvc.Dto.Productionplanning;
using MVC系统mvc.Dto.Purch;
using MVC系统mvc.Dto.RawMater;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC系统mvc.Controllers
{
   
    /// <summary>
    /// 生产计划控制器
    /// </summary>
    public class ProductionplanningController : Controller
    {
        private readonly IConfiguration _configuration;

        public ProductionplanningController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 生产计划
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowProductionplanning()
        {
            return View();
        }
        /// <summary>
        /// 排程
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowProd()
        {
            return View();
        }
        /// <summary>
        /// 生产计划显示
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ShowMaterialss(ProductionplanningDto model)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(model.token);
            string url = _configuration["Url"] + "mapi/api/Production/Show?Pageindex="+model.Pageindex+"&Pagesize="+model.Pagesize+"&ProductionPlanNumber="+model.ProductionPlanNumber+"&ProductionStatus="+model.ProductionStatus;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        ///作废
        /// </summary>
      
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ZuoFeiPros(int ProductionPlanId, string token)
        {
            
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:45234/api/Production/ZuoFeiPro?ProductionPlanId="+ ProductionPlanId;
            string url = _configuration["Url"] + "mapi/api/Production/ZuoFeiPro?ProductionPlanId=" + ProductionPlanId;
            var response = await httpClientWrapper.PostAsync(url, ProductionPlanId.ToString());
            return Json(response);
        }
        /// <summary>
        /// 反填生产计划
        /// </summary>
        /// <returns>JsonResult</returns>
        [HttpGet]
        public async Task<ActionResult> ByidPro(int ProductionPlanId,string token)
        {

            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            //string url = "http://localhost:45234/api/Production/GetByPro?ProductionPlanId="+ ProductionPlanId;
            string url = _configuration["Url"] + "mapi/api/Production/GetByPro?ProductionPlanId=" + ProductionPlanId;
            var response = await httpClientWrapper.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 排程
        /// </summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UpdateProcessPlan(UpdateProDto model,string token)
        {

            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);

            //string url = "http://localhost:45234/api/Production/UpdateProductionPlan?ProductionPlanId=" + model.ProductionPlanId + "&StartingDate=" + model.StartingDate + "&EndingDate=" + model.EndingDate+ "&ProductionStatus="+ model.ProductionStatus;
            string url = _configuration["Url"] + "mapi/api/Production/UpdateProductionPlan?ProductionPlanId=" + model.ProductionPlanId + "&StartingDate=" + model.StartingDate + "&EndingDate=" + model.EndingDate + "&ProductionStatus=" + model.ProductionStatus;
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.PostAsync(url, model.ProductionPlanId.ToString());
            return Json(response);

        }

    }
}
